﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;
using Library.UI;
using Library.UI.Form;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraEditors;
using DevExpress.XtraBars.Helpers;
using QuanLyDiem.Systems;
using QuanLyDiem.DanhMuc;
using QuanLyDiem.QLDiem;
namespace QuanLyDiem
{
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
        //    SkinHelper.InitSkinGallery(rgbiSkins, true);
            try
            {
                Program.ConnectionString = DbHelper.GetConnectionString();

                Context db = new Context();
                db.ExecuteQuery<string>(String.Format(DbHelper.FORMATGETTABLES, Properties.Settings.Default.DB));
            }
            catch (Exception)
            {
                INotify.ShowWarning("Không thể mở kết nối đến máy chủ.", "Kết nối máy chủ thất bại");

                if (IForm.ShowDialogForm(new QuanLyDiem.Systems.frmConfig(), FormWindowState.Normal, System.Windows.Forms.FormBorderStyle.None) != System.Windows.Forms.DialogResult.OK)
                {
                    Environment.Exit(0);
                }
            }
        }

        public DevExpress.XtraBars.Ribbon.GalleryControl rgbiSkins { get; set; }

        private void Form1_Load(object sender, EventArgs e)
        {
            xtraTabControl1.CloseButtonClick += (sender3, e3) =>
            {
                DevExpress.XtraTab.XtraTabControl xtraTabControl = sender3 as DevExpress.XtraTab.XtraTabControl;
                DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs arg = e3 as DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs;
                (arg.Page as DevExpress.XtraTab.XtraTabPage).Dispose();
            };
            btnDangNhap.PerformClick();  
        }

        private void btnDangNhap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var result = IForm.ShowDialogForm(new QuanLyDiem.Systems.frmLogin(), FormWindowState.Normal, System.Windows.Forms.FormBorderStyle.None);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                btnDangNhap.Enabled = false;
                btnDangXuat.Enabled = true;
            }
            else
            {
                try
                {
                    Environment.Exit(0);
                }
                catch (Exception)
                {
                    Application.ExitThread();
                }
            }
        }

        private void btnThoat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Close();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            CTDaoTao a = new CTDaoTao();
            a.ShowDialog();
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmMonHoc a = new frmMonHoc();
            a.ShowDialog();
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmKhoa a = new frmKhoa();
            a.ShowDialog();
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmSinhVien a = new frmSinhVien();
            a.ShowDialog();
        }

        private void btnTaoLopHocPhan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTaoLopHocPhan a = new frmTaoLopHocPhan();
            a.ShowDialog();
        }
    }
}
